const express = require("express");
const cookieParser = require('cookie-parser');
const app = express();
// 将cookie的值解析挂载到req.cookies上
app.use(cookieParser());


app.get('/index', (req, res) => {
    // 在服务器设置cookie
    res.cookie('name', 'tom', {
        maxAge: 1000 * 60 * 60
    });
    res.send('test 设置 req.cookies');
})

app.get('/second', (req, res) => {
    // req.cookies获取cookie值
    console.log(req.cookies);
    res.send('获取前台传过来的cookie！！');
})
app.get('/third', (req, res) => {
    // 删除cookie
    res.clearCookie('name');
    res.send('remove cookie');
})


app.listen(3000, err => {
    if (!err) console.log('serverq启动');
    else console.log(err);
})